package com.li.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import com.li.client.entities.BookInfo;

public class Test {
	public void processEnrollment(String path) {
		InputStream in = null;
		try {
			File file = new File(path);
			in = new FileInputStream(file);
			Workbook wb = WorkbookFactory.create(in);
			Sheet sheet = wb.getSheetAt(0);
			Iterator<Row> rowIterator = sheet.rowIterator();
			rowIterator.next();
			
			List<BookInfo> bookList = new ArrayList<BookInfo>();
			
			while(rowIterator.hasNext()) {
				BookInfo bi = new BookInfo();
				
				Row r = rowIterator.next();
				bi.setBookName(r.getCell(0).getStringCellValue());
				bi.setIsbnCode(r.getCell(1).getStringCellValue());
				bi.setBookPrice(new BigDecimal(r.getCell(3).getNumericCellValue()));
				bookList.add(bi);
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			
		}
	}
	
	public static void main(String[] args) {
		new Test().processEnrollment("C:\\apps\\workspace\\gwtTest\\LibSystem\\war\\csv\\b.xls");
	}
}
